---测试服请求入口
local d = Ding
local app = {}

local INC_LIST = {
    ["/gate"] = "apps.authing"
}

local ROUTER_MAP_LIST = {
    ["/gate"] = {
        {'/signup', 'GET'}, 
        {'/login', 'GET'},
        {'/third/login/wx', 'GET'}, 
        {"/third/login/github", 'GET'}, 
        {'/third/login_callback', 'GET'},
        {"/reg", "POST"}, 
    }
}

local function load_plugin_app(pluginname)

end

-- 程序执行入口
local function main()
    local svr -- chk router
    ngx.log(ngx.INFO, "Hello")
    ngx.log(ngx.INFO, "api locatio->", ngx.var.location)
    local app_src = INC_LIST[ngx.var.location]
    if app_src then
        svr = require(app_src).new(ROUTER_MAP_LIST[ngx.var.location])
    end
    svr:run()
end

local function fmt_traceback_str(msg)
    local FMT_STR = [[

================
API LUA TRACEBACK:
%s
%s
================
    ]]
    return string.format(FMT_STR, msg, debug.traceback())
end

function __G__TRACKBACK__(msg)
    local fmt_str = fmt_traceback_str(msg)
    ngx.say(fmt_str)
    d.Logger:error(fmt_str)
end

app.run = function()
    xpcall(main, __G__TRACKBACK__)
end

return app
